/* Start Header
*****************************************************************/
/*!
\file   Client.h
\author <Liu Wei Long, weilong.liu, 250002510>
        <Liu Zhi Yang, zhiyang.liu, 300000111>
\par    <email: weilong.liu\@digipen.edu> 
        <email: zhiyang.liu\@digipen.edu> 
\date   <Apr 3, 2012>
\brief
Copyright (C) 2012 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the
prior written consent of DigiPen Institute of Technology is prohibited.
*/
/* End Header
*******************************************************************/
#ifndef _CLIENT_H_
#define _CLIENT_H_

#include "WinsockHeaders.h"
#include "TSSocket.h"
#include "Timer.h"
#include <vector>
#include <fstream>

class Client
{
public:
	Client(std::string config);
	~Client(void);

	bool Setup(void);
	bool Run(void);
	bool SendUserName(void);
	void GetListOfSharedFiles(void);
	void CreateReceivingThread(void);
	static DWORD WINAPI ReceiveUDPDataLoop(void* args);
  bool WaitForAck(float timeOutInterval, unsigned int ackNum);

	// Parsers
	void MessageParser(const char* dataFromServer);
	int InputParser(); // Parses client's input

	// Displays help info
	void PostHelpInfo();

  // Networking variables
	char m_ServerPortNumberStr[10];
	char m_ServerIPAddrStr[32];
	char m_UDPPortNumberStr[10];
  // String & int equivalents
  std::string m_serverIP;
  int m_serverPort;
  int m_UDPport;

  bool isSending;

private:
  Timer* m_clientTimer;
  LARGE_INTEGER m_startIdleTimer;
	bool m_Terminate;   // Boolean to determine when to stop receiving and sending loops
  bool m_readyToSend; // Only sends at the end of every game loop

	TSSocket *m_UDPClientSocket; // UDP socket to connect to other clients
	std::vector<HANDLE> mFileTransferThreadHandles;
	HANDLE mReceivingThreadHandle;
};

#endif

